package cn.est.controller;
import cn.est.pojo.MaintainOrder;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.MaintainOrderService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/maintainOrder")
public class MaintainOrderController {

    @Resource
    private MaintainOrderService maintainOrderService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<MaintainOrder> searchMaintainOrder(@RequestParam Map<String,Object> param) {
        Page<MaintainOrder> maintainOrderPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            maintainOrderPage  = maintainOrderService.queryMaintainOrderPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return maintainOrderPage;
    }

    @RequestMapping("/saveOrUpdateMaintainOrder")
    @ResponseBody
    public Result saveOrUpdateMaintainOrder(MaintainOrder maintainOrder){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(maintainOrder.getId())){
                flag=maintainOrderService.qdtxAddMaintainOrder(maintainOrder);
            }else{
                flag=maintainOrderService.qdtxModifyMaintainOrder(maintainOrder);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getMaintainOrderById")
    @ResponseBody
    public Result getMaintainOrderById(Long id){
        Result result= ResultUtils.returnSuccess();
        MaintainOrder maintainOrder=null;
        try {
            maintainOrder=maintainOrderService.getMaintainOrderById(id);
            result.setData(maintainOrder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveMaintainOrder")
    @ResponseBody
    public Result batchRemoveMaintainOrder(String ids){
        Integer flag=0;
        try {
            flag=maintainOrderService.qdtxBatchDeleteMaintainOrder(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeMaintainOrderById")
    @ResponseBody
    public Result removeMaintainOrderById(Long id){
        Integer flag=0;
        try {
            flag=maintainOrderService.qdtxDeleteMaintainOrderById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
